﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using GeoWeb.Common;
using System.Data;

namespace GeoWeb.Demo.Commons
{
    public partial class GeoIListHelper_Demo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            funGeoIListHelper();
        }

        #region GeoIListHelper
        private void funGeoIListHelper()
        {
            //创建一个datatable
            Dictionary<string, Type> colDict = new Dictionary<string, Type>();
            colDict.Add("ID", typeof(Int32));
            colDict.Add("Name", typeof(string));
            DataTable newDT = IListHelper.CreateTable(colDict);
            DataRow dr = newDT.NewRow();
            dr[0] = 0;
            dr[1] = "keily";
            newDT.Rows.Add(dr);

            //实体 转 datatable 
            var vperson = new List<Person>() { new Person(1,"张三"),
                new Person(2,"李四"), new Person(3,"王五"), 
                new Person(4,"赵六"), new Person(5,"小齐") };
            DataTable vDt = IListHelper.Enitiy2DataTable(vperson);

            //dattable 转 实体
            IList<Person> listPerson = IListHelper.Dt2List<Person>(newDT);

            //合并 datatable
            DataTable mergeDT = IListHelper.MergeDataTable(newDT, vDt);

            //过滤 datatable
            DataRow[] filterDR = IListHelper.SelectRows(mergeDT, "ID>3");

            
            //将页面post的参数键值对序列化给实体一一赋值
            System.Collections.Specialized.NameValueCollection collection = Request.Params;
            //System.Collections.Specialized.NameValueCollection collection = new System.Collections.Specialized.NameValueCollection();
            //模拟url post过来的参数
            collection.Add("ID", "101");
            collection.Add("Name", "张伟");
            collection.Add("Age", "25");
            collection.Add("Phone", "18696114719");
            //--------------

            Person webPerson = IListHelper.WebForm2Entity<Person>(collection);


        }
        #endregion
    }
}